<extend name="layout/main" />

<block name="HEADER">

</block>

<block name="CONTENT">
	<control:grid id="grid" />
</block>

<block name="FOOTER">
	<script type="text/javascript">
		var shop_id = <php>echo $userInfo['shop_id'];</php>;
		var page = (function(ns){
     
		    //页面初始化
		    ns.init=function(){
				if(shop_id) $("#grid .layui-table-tool-temp .layui-btn-sm").remove();
		    }
		    
		    //新增
		    ns.add=function(){
		    	var filter = {
		            url:$.getModule('edit'),
		            oid:"",
		            mode:1
		        }
		        $.openIframe(filter, "新增",['850px', '90%']);
		    }
		    
		    //编辑
		    ns.edit=function(){
		    	var selectedRow = grid.getSelectedRows()[0];
		        var filter = {
		            url: $.getModule('edit'),
		            oid: selectedRow.id ,
		            mode:2
		        }
		        $.openIframe(filter, "编辑",['950px', '90%']);
		    }  
		    
		    //删除
		    ns.del =function(){
		    	if( !grid.isSelected() ){
		    		return false;
		    	}
		    	$.confirm("确定删除？", function(){
		    		$.ajaxs('/admin/v1/Store/del',{
			    		ids:grid.getSelectedColumnValue('id')
			    	},function(res){
			    		$.toast(1,"已删除！");
			    		grid.load();
			    	});
		    	});
		    }
		    
		    //下拉移动  type: 1 = 上移 ,  type: 2 = 下移
		    ns.move = function(type){
		    	grid.adjustSort(type,"sort_no");
		    }
		    
		    
		    //打开店员
		    ns.openClerk =function(){
		    	var selectedRow = grid.getSelectedRows()[0];
		    	if(!selectedRow){
		    	    $.toast(0,'请选择数据！');
		    	    return false;
		    	}
		        var filter = {
		            url: 'modules/shop/staff/edit',
		            mode:2,
		            shop_id:selectedRow['id']
		        }
		        $.openIframe(filter,"编辑",['960px', '520px']);
		    }
		    
		    //打开商品
		    ns.openGoods =function(){
		    	var selectedRow = grid.getSelectedRows()[0];
		    	if(!selectedRow){
		    	    $.toast(0,'请选择数据！');
		    	    return false;
		    	}
		        var filter = {
		            url: $.getModule('goods'),
		            mode:2,
		            shop_id:selectedRow['id']
		        }
		        $.openIframe(filter,"门店商品",['900px', '580px']);
		    }
		    
		    
		    //更新密码
		    ns.updatePwd=function(){
		    	var selectedRow = grid.getSelectedRows()[0], pwdForm;
		    	if(!selectedRow){
		    		$.toast(0,"请先选择用户！");
		    		return;
		    	}
		       function successFn(){
		    		pwdForm = layui.forms.render("updatePwdForm","/modules/spreadMng/list/config.xml",{
		    		    mode:2,
		    		    oid:selectedRow.id
		    		});
		    	}
		    	function yesFn(index){
		    		pwdForm.save(1).then(function(res){
		            	grid.load();
		            	layer.close(index);
		            });
		    	}
		    	var html="<div id='updatePwdForm'></div>";
		    	$.openModalDialog(html,"重置密码",successFn,yesFn,["400px","250px"])
		    }
		   
		    return ns;
		}({}));
		
		
		$(function(){ page.init();  });

	</script>
</block>